//友元的使用
//求两点之间的距离

#include<iostream>
using namespace std;
#include<math.h>

class point;    //前向声明 

class pointdis
{
public:
    double distance(point &a,point &b); 
};

class point
{
public:
    
    point(double x, double y)
    {
        _x = x;
        _y = y;
    }
    friend class pointdis; //定义为友元类 ，则该类中的所有成员函数都可以访问point中的数据
    // friend double pointdis::distance(point &a,point &b);     //友元声明，允许其访问我的私有成员
private:
    double _x,_y;
};


double pointdis::distance(point &a,point &b) //求两点距离
{
    double dx = a._x - b._x;
    double dy = a._y - b._y;
    return sqrt(dx*dx + dy*dy);
}


int main ()
{
    // point a;
    point p1(3.0, 4.0), p2(6.0, 8.0);
    pointdis pd;
    float d = pd.distance(p1,p2);
    cout << "distance is " << d<< endl;
    return 0;
}